package com.audaque.springboot.foshanupload.web.logindemo.controller;

import com.audaque.springboot.foshanupload.authcore.anno.AnonymousAccessAnno;
import com.audaque.springboot.foshanupload.authcore.anno.NeedLoginAnno;
import com.audaque.springboot.foshanupload.authcore.model.currentUser.TransmittableThreadLocalCurrentUser;
import com.audaque.springboot.foshanupload.authcore.service.inface.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author zgb
 * @desc ...
 * @date 2022-06-28 21:53:02
 */

@Slf4j
@RestController
public class RootController {

    @Autowired
    private LoginService loginService;

    @GetMapping("/")
    public String root() {
        return "root";
    }

    @AnonymousAccessAnno
    @GetMapping("/sb")
    public String sb() {
        return "sb";
    }

    @GetMapping("/error")
    public String error() {
        return "error";
    }

    @NeedLoginAnno
    @GetMapping("/getCurrentUser")
    public TransmittableThreadLocalCurrentUser getCurrentUser(HttpServletRequest request, HttpSession httpSession) {
        long threadId = Thread.currentThread().getId();
        log.debug("/logindemo/getCurrentUser:threadId：" + threadId);
        log.debug("{\n" +
                "    \"userBeheaver\": {\n" +
                "        \"id\": \"1\",\n" +
                "        \"username\": \"2\",\n" +
                "        \"beheaver\": \"3\"\n" +
                "    }\n" +
                "}");
        int i = 1 / 0;
        return loginService.getCurrentUser();
    }

}


